﻿using System.Collections.Generic;
using Unis.Framework.Core.Exceptions;
using Unis.ORM.Mapping;

namespace Unis.Framework.ORM.Mapping
{
    public class QueryParameterMappings : Dictionary<string, QueryParameterMappingInfo>
    {
        // Fields
        private string _DefaultTableAlias;

        // Methods
        public QueryParameterMappings()
        {
        }

        public QueryParameterMappings(string defaultTableAlias, params string[] paramterMappingInfo)
        {
            this._DefaultTableAlias = defaultTableAlias;
            if ((paramterMappingInfo != null) && (paramterMappingInfo.Length > 0))
            {
                foreach (string str in paramterMappingInfo)
                {
                    string[] strArray = str.Split(new char[] { ',' });
                    if (strArray.Length == 2)
                    {
                        base.Add(strArray[0], new QueryParameterMappingInfo(strArray[0], strArray[1]));
                    }
                }
            }
        }

        public QueryParameterMappingInfo Add(QueryParameterMappingInfo mappingInfo)
        {
            if (base.ContainsKey(mappingInfo.PropertyName))
            {
                throw new APPException(string.Format("在获取QueryParamMappings的时候存在重复的配置名称：{0}", mappingInfo.PropertyName), APPMessageType.SysErrInfo);
            }
            base.Add(mappingInfo.PropertyName, mappingInfo);
            return mappingInfo;
        }

        // Properties
        public string DefaultTableAlias
        {
            get
            {
                return this._DefaultTableAlias;
            }
            set
            {
                this._DefaultTableAlias = value;
            }
        }
    }
}
